home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / Extension Shell 1.5 / Sample Extensions (1.5) / Bell Test ƒ / MenuSelect.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-12  |  3.9 KB  |  212 lines  |  [TEXT/R*ch]

  1. /*    NAME:
  2.         MenuSelect.c
  3.  
  4.     WRITTEN BY:
  5.         Dair Grant
  6.                 
  7.     DESCRIPTION:
  8.         This file contains a code resource to be installed as a Trap Patch.
  9.  
  10.     NOTES:
  11.         We are applied as a patch to MenuSelect, and cause the Mac to play
  12.         a sound when About... is selected from the Apple menu.
  13.  
  14.     ___________________________________________________________________________
  15. */
  16. //=============================================================================
  17. //        Include files                                                                     
  18. //-----------------------------------------------------------------------------
  19. #include <Gestalt.h>
  20. #include <ToolUtils.h>
  21. #include "A4Stuff.h"
  22. #include "SetupA4.h"
  23. #include "BT Constants.h"
  24. #include "BT AddrsTable.h"
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40. //=============================================================================
  41. //        Private defines                                                                 
  42. //-----------------------------------------------------------------------------
  43. #define AppleSymbol                0xF0                // The Apple symbol
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. //=============================================================================
  60. //        Types                                                                 
  61. //-----------------------------------------------------------------------------
  62. typedef pascal long (*MenuSelectProcPtr)(Point thePoint);
  63. typedef pascal void (*PlaySoundProcPtr)(void);
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79. //=============================================================================
  80. //        Global Variables                                                                 
  81. //-----------------------------------------------------------------------------
  82. MenuSelectProcPtr    gPrevMenuSelect;
  83. PlaySoundProcPtr    gPlaySound;
  84. Boolean                gAlreadyRan = false;
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. //=============================================================================
  101. //        Private function prototypes                             
  102. //-----------------------------------------------------------------------------
  103. pascal long        main(Point thePoint);
  104. short            IsAppleMenu(MenuHandle theMenu);
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120. //=============================================================================
  121. //        main : Entry point to our code resource.                                                                 
  122. //-----------------------------------------------------------------------------
  123. //        Note :    We call the original MenuSelect, and then play a sound if the
  124. //                item chosen was About... in the Apple menu.
  125. //-----------------------------------------------------------------------------
  126. pascal long main(Point thePoint)
  127. {    long                oldA4, retVal;
  128.     MenuHandle            theMenu;
  129.     short                theMenuID;
  130.     BTAddressTable        *theAddressTable;
  131.     
  132.  
  133.  
  134.  
  135.     // Set up A4
  136. #ifndef powerc
  137.     oldA4 = SetCurrentA4();
  138. #endif
  139.     
  140.     
  141.     
  142.     // If we've not already been called, do our one time initialisation stuff
  143.     if (!gAlreadyRan)
  144.         {
  145.         Gestalt(kBellTestAddressTable, (long *) &theAddressTable);        
  146.         gPrevMenuSelect    = (MenuSelectProcPtr) ((long) theAddressTable->theTable[kMenuSelect]);
  147.         gPlaySound        = (PlaySoundProcPtr) ((long) theAddressTable->theTable[kPlaySound]);
  148.         gAlreadyRan        = true;
  149.         }
  150.  
  151.     
  152.     
  153.     // Call the original MenuSelect()
  154.     retVal = gPrevMenuSelect(thePoint);
  155.  
  156.  
  157.     
  158.     // If the user selected something, check for the Apple menu
  159.     theMenuID = HiWord(retVal);
  160.     if (theMenuID)
  161.         {
  162.         // If it's the Apple menu, and the first item on it,
  163.         // call our play-the-sound routine
  164.         theMenu = GetMHandle(theMenuID);
  165.         if (IsAppleMenu(theMenu) && (LoWord(retVal) == 1))
  166.             gPlaySound();
  167.         }
  168.     
  169.     
  170.  
  171.     // Restore A4 and return
  172. #ifndef powerc
  173.     SetA4(oldA4);
  174. #endif
  175.     return(retVal);
  176. }
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192. //=============================================================================
  193. //        IsAppleMenu : Is a given menu the Apple menu?
  194. //-----------------------------------------------------------------------------
  195. short IsAppleMenu(MenuHandle theMenu)
  196. {    
  197.  
  198.  
  199.     // If we don't have a menu, it can't be the Apple menu
  200.     if (!theMenu)
  201.         return(false);
  202.     
  203.     
  204.     // If the menus name is one character long, and that character
  205.     // is an Apple, it's the Apple menu    
  206.     if (((*theMenu)->menuData[0] == 1) &&
  207.             (((*theMenu)->menuData[1] == 0x14) || ((*theMenu)->menuData[1] == AppleSymbol)))
  208.         return(true);
  209.     else
  210.         return(false);
  211. }
  212.